package com.sgy;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sgy.entity.ClientFilterUrl;
import com.sgy.mapper.ClientFilterUrlMapper;
import com.sgy.config.SystemProperties;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

/**
 * @author shenguangyang
 * @date 2022-08-14 6:10
 */
@Component
public class ClientRunner implements ApplicationRunner {
    @Resource
    private SystemProperties systemProperties;

    @Resource
    private ClientFilterUrlMapper clientFilterUrlMapper;

    @Resource(name = "myThreadPoolTaskExecutor")
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;

    @PostConstruct
    public void init() {

    }

    @Override
    public void run(ApplicationArguments args) {
        List<ClientFilterUrl> clientFilterUrls = clientFilterUrlMapper.selectList(new QueryWrapper<>());
        for (ClientFilterUrl clientFilterUrl : clientFilterUrls) {
            ClientFilterUrlMgt.add(clientFilterUrl);
        }

        Client client = new Client(systemProperties, threadPoolTaskExecutor);
        client.start();
    }
}
